<!DOCTYPE html>
<html lang="fangkuang">
    <head>
        <style>
  #f1{width: 100px;height: 100px;border: solid 2px green;position: absolute;}
        </style>
    
    <script>
        window.onload=function(){
         var f1=document.getElementById("f1");
         document.onkeydown=function(a){
             a =a || window.event;
             var speed=10;
         
         switch(a.keyCode){
             case 37:
                 f1.style.left=f1.offsetLeft -speed+"px";
                 break;
             case 38:
                 f1.style.top=f1.offsettop -speed+"px";
                 break;
             case 39:
                 f1.style.left=f1.offsetLeft + speed+"px";
                 break;
             case 40:
                 f1.style.top=f1.offsetTop + speed+"px";
                 break;
         }
         }
        }
     </script>
     </head>
    <body>
        <div id="f1"></div>
    </body>
</html>